package logic

import (
	"context"
	"doc-manage/models/mysql"
	"errors"

	"doc-manage/docrppc/docrppc"
	"doc-manage/docrppc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowLogic {
	return &ShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShowLogic) Show(in *docrppc.ShowRequest) (*docrppc.ShowResponse, error) {
	// todo: add your logic here and delete this line
	var doc mysql.Doc
	err := doc.FindDocId(mysql.DB, in.DocsId)
	if err != nil {
		return nil, errors.New("数据不存在")
	}
	err = doc.ShowDoc(mysql.DB, in.DocsId)
	if err != nil {
		return nil, err
	}
	return &docrppc.ShowResponse{
		Name:   doc.Name,
		Form:   doc.From,
		Image:  doc.Image,
		DocsId: int64(doc.ID),
	}, nil
}
